/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uvexposureapplication.sensors;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import uvexposureapplication.eventrouting.Producer;
import uvexposureapplication.eventrouting.elvin.ElvinProducer;
import uvexposureapplication.sensors.data.SensorsDataFormat;

/**
 *
 * @author matthieukluj
 */
public abstract class AbstractSensor implements Runnable {

    public List<SensorsDataFormat> initData;
    public String name;
    public Producer producer;

    public AbstractSensor(String name, String server) {
        this.name = name;
        this.producer = new ElvinProducer(server);
    }

    @Override
    public void run() {
        while (true) {
            for (SensorsDataFormat data : initData) {
                int timeTotal = data.getTime();
                int timeElapsed = 1;
                while (timeElapsed <= timeTotal) {
                    this.report(data.getValue(), Integer.toString(timeElapsed));
                    timeElapsed++;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(AbstractSensor.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    }

    public abstract void report(String value, String timeElapsed);

    public void StopSensor() {
        System.out.println("Stopping Sensors");
        System.exit(0);
    }
}
